use ggez::{glam::Vec2, Context, graphics, mint::Point2};



pub struct Wave {
    location: Vec2,
    phase: f32,
    freq: f32,
    amplitude: f32,
    len: f32,
    speed: f32,
}

impl Wave {
    pub fn new(location: Vec2, phase: f32, freq: f32, amplitude: f32, len: f32, speed: f32) -> Wave {
        Wave { location, phase, freq, amplitude, len, speed}
    }

    pub fn update(&mut self) -> () {
        self.phase += self.speed;
    }

    pub fn display(&self, ctx: &mut Context, canvas : &mut graphics::Canvas) -> () {
        let mut angle = self.phase;
        for i in 0..((self.len as i32)/10) {
            let x = (i*10) as f32;
            let y = angle.sin()*self.amplitude+self.amplitude;
            let p = Point2{x, y};
            angle += self.freq;

            let circle = graphics::Mesh::new_circle(
                ctx, 
                graphics::DrawMode::stroke(2.0), 
                p, 
                20.0, 
                0.1, 
                graphics::Color::BLACK).unwrap();
            canvas.draw(&circle, graphics::DrawParam::default().dest(self.location));

            let circle = graphics::Mesh::new_circle(
                ctx, 
                graphics::DrawMode::fill(), 
                p, 
                20.0, 
                0.1, 
                graphics::Color::new(0.0, 0.0, 0.0, 0.4)).unwrap();
            canvas.draw(&circle, graphics::DrawParam::default().dest(self.location)); 
        }
    }
}